package com.bestcem.xm.user.grpc.client.converter;

import com.bestcem.xm.common.core.uitls.GrpcDateUtil;
import com.bestcem.xm.om.grpc.v1.services.Platform;
import com.bestcem.xm.user.grpc.client.dto.UserPlatformDTO;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;

import java.util.Objects;

/**
 * 合作商服务对象转换
 *
 * @author qiongyu.cui <qiongyu.cui@idiaoyan.com>
 * @version v1.0
 * @date 2022/7/1 14:57
 */
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class UserPlatformGrpcConvert {

    /**
     * 合作商对象转换
     *
     * @param platform 合作商信息
     * @return com.bestcem.xm.user.grpc.client.dto.UserPlatformDTO
     * @author cuiqiongyu <qiongyu.cui@idiaoyan.cn>
     * @date 2022/07/01 14:59
     */
    public static UserPlatformDTO platformToDto(Platform platform) {
        if (Objects.isNull(platform)) {
            return null;
        }

        UserPlatformDTO platformDTO = new UserPlatformDTO();
        platformDTO.setId(platform.getId());
        platformDTO.setCode(platform.getCode());
        platformDTO.setName(platform.getName());
        platformDTO.setUrl(platform.getUrl());
        platformDTO.setOrgId(platform.getOrgId());
        platformDTO.setSource(platform.getSourceValue());
        platformDTO.setLinkName(platform.getLinkName());
        platformDTO.setLinkPhone(platform.getLinkPhone());
        platformDTO.setLinkEmail(platform.getLinkEmail());
        platformDTO.setSupporter(platform.getSupporter());
        platformDTO.setExpireTime(GrpcDateUtil.getDate(platform.getExpireTime()));
        platformDTO.setAesKey(platform.getAesKey());
        platformDTO.setContactsName(platform.getContactsName());
        platformDTO.setContactsPhone(platform.getContactsPhone());
        platformDTO.setContactsEmail(platform.getContactsEmail());
        platformDTO.setStatus(platform.getStatusValue());
        if (platform.hasContactsQrcode()) {
            platformDTO.setContactsQrcode(platform.getContactsQrcode());
        }
        if (platform.hasSampleCode()) {
            platformDTO.setSampleCode(platformDTO.getSampleCode());
        }
        return platformDTO;
    }

}
